package com.ytkj.digitalConstruction.rabbit;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* rabbitmq配置类
* 
* @author yf
* @author momei
* @date 创建时间：2017年12月8日 下午4:02:19 
* @version 1.0   
*/
@Configuration
public class RabbitConfig {
    
   @Autowired	
   private BaseVar baseVar;
   
 
    /**
     * 声明普通消息队列
     * 
     * @return 队列对象
     */
    @Bean
    public Queue messageQueue() {
        return new Queue(baseVar.getMessageQueue(), true); 
    }
    

    /**
     * 声明丁丁消息队列
     * 
     * @return 队列对象
     */
    @Bean
    public Queue messageDingQueue() {
        return new Queue(baseVar.getMessageDingQueue(), true);
    }
    
    /**
     * 声明消息详情队列
     * 
     * @return 队列对象
     */
    @Bean
    public Queue messageDetailsQueue() {
        return new Queue(baseVar.getMessageDetailsQueue(), true); 
    }
    
    /**
     * 声明用户队列
     * 
     * @return
     */
    public Queue userQueue(){
    	return new Queue(baseVar.getUserQueue(), true); 
    }
    
    /**
     * 声明部门队列
     * 
     * @return
     */
    public Queue departmentQueue(){
    	return new Queue(baseVar.getDepartmentQueue(), true); 
    }

    /**
     * 声明转换器
     * 
     * @return 类型为TopicExchange的转换器对象
     */
    @Bean
    TopicExchange topicExchange() {
        return new TopicExchange("topicExchange");
    }
    
    /**
     * 声明转换器
     * 
     * @return 类型为DirectExchange的转换器对象
     */
    @Bean
    DirectExchange directExchange() {
    	return new DirectExchange("directExchange");
    }
    
    /**
     * 绑定普通消息队列
     * 
     * @return 
     */
    @Bean
    public Binding bindingMessageQueue() {
       return BindingBuilder.bind(messageQueue()).to(directExchange()).with(baseVar.getRoutingkeyMessage()); 	
    }

    /**
     * 绑定丁丁消息队列
     * 
     * @return
     */
    @Bean
    public Binding bindingMessageDingQueue() {
        return BindingBuilder.bind(messageDingQueue()).to(directExchange()).with(baseVar.getRoutingkeyDingMessage());
    }
    
    /**
     * 绑定消息详情队列
     * 
     * @return
     */
    @Bean
    public Binding bindingMessageDetailsQueue() {
        return BindingBuilder.bind(messageDetailsQueue()).to(directExchange()).with(baseVar.getRoutingkeyMessageDetails());
    }
    
    /**
     * 绑定用户队列
     * 
     * @return
     */
    @Bean
    public Binding bindingUserQueue() {
        return BindingBuilder.bind(userQueue()).to(directExchange()).with(baseVar.getRoutingkeyUser());
    }
    
    /**
     * 绑定用户队列
     * 
     * @return
     */
    @Bean
    public Binding bindingDepartmentQueue() {
        return BindingBuilder.bind(departmentQueue()).to(directExchange()).with(baseVar.getRoutingkeyDepartment());
    }
    
    
    
}
